package com.hspedu.newData.LCR;

import com.hspedu.newData.dmsxl.ds.TreeNode;

import java.util.ArrayDeque;
import java.util.Queue;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-26 
 * @Version: 1.0
 */

public class LCR45找树左下角的值 {
    public int findBottomLeftValue(TreeNode root) {

        Queue<TreeNode> queue = new ArrayDeque<>();
        queue.offer(root);
        int res = root.val;
        while(!queue.isEmpty()){

            int len = queue.size();
            int i = len;
            while (len>0){
                TreeNode node = queue.poll();
                if (i==len){
                    res = node.val;
                }

                if (node.left!=null) queue.offer(node.left);
                if (node.right!=null) queue.offer(node.right);

                len--;
            }

        }
        return res;
    }
}
